-
-
Notifications
You must be signed in to change notification settings - Fork 696
feat: introduce tsdown, support mixed js & ts in codebase
#2916
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
tsdown, support js & tstsdown, support mixed js & ts in codebase
FloEdelmann
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice, thank you!
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
2nofa11
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If pull request #2931 is merged and incorporated into this PR, it may resolve some of the CI failures!!!
I believe this PR is an excellent fix 😍
This comment was marked as resolved.
This comment was marked as resolved.
# Conflicts: # eslint.config.mjs # package.json
This comment was marked as outdated.
This comment was marked as outdated.
# Conflicts: # lib/plugin.js # tests/lib/rules/block-order.ts # tools/update-lib-plugin.js
FloEdelmann
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's go then 🚀 🙂
ota-meshi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thank you so much!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces tsdown as a build tool to enable gradual migration from JavaScript to TypeScript in the eslint-plugin-vue codebase. It converts several core files to TypeScript (lib/index.ts, lib/meta.ts, lib/processor.ts) while maintaining compatibility with the existing JavaScript files.
Key changes:
- Adds
tsdownbuild configuration and updates CI workflow with a dedicated build job - Converts core plugin files from CommonJS to TypeScript with ESM syntax
- Changes package entry point from
lib/index.jstodist/index.js(built output)
Reviewed changes
Copilot reviewed 12 out of 14 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
| tsdown.config.ts | Configures tsdown build tool with entry point, output format (CJS), and file copy settings |
| tsconfig.json | Updates TypeScript compiler options for modern module resolution (bundler) and ESNext target |
| package.json | Updates main/types entry points to dist directory and adds build script with tsdown |
| .gitignore | Adds dist directory to ignored files |
| .github/workflows/CI.yml | Adds build job and artifact caching for all test jobs |
| lib/index.ts | Converts main entry point from CommonJS to TypeScript with ESM imports |
| lib/meta.ts | Converts meta module to TypeScript using JSON import assertion |
| lib/processor.ts | Converts processor from CommonJS/JSDoc to TypeScript with proper type annotations |
| lib/plugin.js | Updates requires to reference TypeScript files with .default exports |
| tools/update-lib-plugin.js | Updates generated code to require TypeScript files |
| tools/generate-typegen.mjs | Updates import to reference TypeScript source file |
| docs/.vitepress/theme/components/eslint-code-block.vue | Updates import path to reference lib source directory |
Comments suppressed due to low confidence (1)
lib/processor.ts:160
- The
Positiontype is used in the function signature but is not imported or defined anywhere in this file. This will cause a TypeScript compilation error. ThePositiontype should be imported from ESLint's types (e.g.,import type { Linter } from 'eslint'and then useLinter.Position) or defined as an interface in this file.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const plugin = { | ||
| meta: require('./meta'), | ||
| meta: require('./meta.ts').default, |
Copilot
AI
Dec 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using require('./meta.ts').default to import a TypeScript file from a CommonJS module is problematic. After tsdown transpiles the code, the file should be ./meta.js in the dist directory, not ./meta.ts. This will cause a runtime error because the .ts file won't exist in the built output. The require path should reference the transpiled .js file.
| // Load linter. | ||
| const [plugin, { Linter }, vueEslintParser, globals] = await Promise.all([ | ||
| import('../../../..'), | ||
| import('../../../../lib/index'), |
Copilot
AI
Dec 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The import path '../../../../lib/index' attempts to import from the source directory, but with the package.json change, the built output is now in the dist directory. This import should be updated to '../../../../dist/index' or '../../../../lib/index.js' (if the intent is to use the transpiled output), or ensure that Vite/VitePress is configured to handle TypeScript imports from lib/ directory.
| import('../../../../lib/index'), | |
| import('../../../../dist/index'), |
| - name: Restore dist cache | ||
| uses: actions/download-artifact@v6 | ||
| with: | ||
| name: dist |
Copilot
AI
Dec 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The download-artifact action is missing the path parameter to specify where the artifact should be extracted. By default, artifacts are downloaded to the current working directory, but it's unclear if that matches the expected dist location. The path parameter should be explicitly set to dist to ensure the artifact is extracted to the correct location.
| - name: Restore dist cache | ||
| uses: actions/download-artifact@v6 | ||
| with: | ||
| name: dist |
Copilot
AI
Dec 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The download-artifact action is missing the path parameter to specify where the artifact should be extracted. By default, artifacts are downloaded to the current working directory, but it's unclear if that matches the expected dist location. The path parameter should be explicitly set to dist to ensure the artifact is extracted to the correct location.
| '.vue': require('./processor.ts').default, | ||
| vue: require('./processor.ts').default |
Copilot
AI
Dec 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using require('./processor.ts').default to import a TypeScript file from a CommonJS module is problematic. After tsdown transpiles the code, the file should be ./processor.js in the dist directory, not ./processor.ts. This will cause a runtime error because the .ts file won't exist in the built output. The require path should reference the transpiled .js file.
| '.vue': require('./processor.ts').default, | |
| vue: require('./processor.ts').default | |
| '.vue': require('./processor.js').default, | |
| vue: require('./processor.js').default |
| import fs from 'node:fs/promises' | ||
| import { pluginsToRulesDTS } from 'eslint-typegen/core' | ||
| import plugin from '../lib/index.js' | ||
| import plugin from '../lib/index.ts' |
Copilot
AI
Dec 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Importing a TypeScript file (../lib/index.ts) from an ESM module (.mjs) will fail at runtime because Node.js doesn't natively support TypeScript imports without a loader. Since the build script runs typegen before tsdown, this script executes before the TypeScript files are transpiled. Consider using a TypeScript loader, running this script with tsx/ts-node, or restructuring the build process so typegen runs after the build.
| import plugin from '../lib/index.ts' | |
| import plugin from '../lib/index.js' |
| - name: Restore dist cache | ||
| uses: actions/download-artifact@v6 | ||
| with: | ||
| name: dist |
Copilot
AI
Dec 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The download-artifact action is missing the path parameter to specify where the artifact should be extracted. By default, artifacts are downloaded to the current working directory, but it's unclear if that matches the expected dist location. The path parameter should be explicitly set to dist to ensure the artifact is extracted to the correct location.
| - name: Restore dist cache | ||
| uses: actions/download-artifact@v6 | ||
| with: | ||
| name: dist |
Copilot
AI
Dec 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The download-artifact action is missing the path parameter to specify where the artifact should be extracted. By default, artifacts are downloaded to the current working directory, but it's unclear if that matches the expected dist location. The path parameter should be explicitly set to dist to ensure the artifact is extracted to the correct location.
| - name: Restore dist cache | ||
| uses: actions/download-artifact@v6 | ||
| with: | ||
| name: dist |
Copilot
AI
Dec 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The download-artifact action is missing the path parameter to specify where the artifact should be extracted. By default, artifacts are downloaded to the current working directory, but it's unclear if that matches the expected dist location. The path parameter should be explicitly set to dist to ensure the artifact is extracted to the correct location.
| node-version: lts/* | ||
|
|
||
| - name: Install Packages | ||
| run: npm install |
Copilot
AI
Dec 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The build job uses npm install without the --legacy-peer-deps flag, while the lint job uses npm install --legacy-peer-deps. This inconsistency could lead to different dependency resolution and potential build failures. The build job should use the same installation command as other jobs for consistency.
| run: npm install | |
| run: npm install --legacy-peer-deps |
Hi 👋, Vue team!
I've been trying to contribute to
eslint-plugin-vueand recently noticed there might be plans to rewrite it in TypeScript, though things seem to have stalled. I’d like to help move this effort forward.This PR introduces
tsdown, a tool that can gradually transform mixed JavaScript/TypeScript codebases into pure JavaScript output. This allows us to incrementally migrate the entire project to TypeScript. I’ve already successfully rewritten several files — it works well.Going forward, I can split the changes into multiple PRs to make review easier.
If there’s anything you’d like me to adjust in this PR, or if you have any feedback, I’d really appreciate your thoughts! 💚
Related: #2777